<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">

        <div class="layui-form layuimini-form">
            <div class="layui-form-item">
                <label class="layui-form-label required">旧的密码</label>
                <div class="layui-input-block">
                    <input type="password" name="old_password" lay-verify="required" lay-reqtext="旧的密码不能为空" placeholder="请输入旧的密码" value="" class="layui-input">
                    <tip>填写自己账号的旧的密码。</tip>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label required">新的密码</label>
                <div class="layui-input-block">
                    <input type="password" name="new_password" lay-verify="required" lay-reqtext="新的密码不能为空" placeholder="请输入新的密码" value="" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">新的密码</label>
                <div class="layui-input-block">
                    <input type="password" name="again_password" lay-verify="required" lay-reqtext="新的密码不能为空" placeholder="请输入新的密码" value="" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    layui.use(['form', 'miniPage','store','jquery'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.jquery,
            store = layui.store,
            miniPage = layui.miniPage;

        form.render();

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var DISABLED = 'layui-btn-disabled';
            $(':button').addClass(DISABLED);
            $(':button').attr('disabled', 'disabled');
            axios({
                url:"/user/editPassword",
                method:"post",
                data:data.field
            }).then(res=>{
                if(res.code==0){
                    layer.msg(res.message,{
                        icon:6,
                        time:2000
                    },function () {
                        store.clear()
                        window.location="/page/login.html"
                    })
                }else{
                    layer.msg(res.message,{
                        icon:5,
                        anim:6,
                        time:2000
                    });
                    $(':button').removeClass(DISABLED);
                    $(':button').removeAttr('disabled');
                }
            }).catch(error=>{
                $(':button').removeClass(DISABLED);
                $(':button').removeAttr('disabled');
            })
          
            return false;
        });

    });
</script>